/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2018-01-6 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.h5.controller.user;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.itttq.gshop.domain.po.UserScorePo;
import com.itttq.gshop.domain.to.PageParamTo;
import com.itttq.gshop.domain.to.ResultPageTo;
import com.itttq.gshop.generic.cmpt.annotation.Auth;
import com.itttq.gshop.generic.connector.IUserScoreConnector;
import com.itttq.gshop.generic.controller.GenericController;
@Auth
@RestController
@RequestMapping("score")
public class ScoreController extends GenericController {
	private static final long serialVersionUID = 434162097107975110L;
	@Autowired
	private IUserScoreConnector userScoreConnector;
	
	/**
	 * 根据条件查询UserScorePo对象，并分页
	 * 
	 * @param userScore
	 * @param request
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("list.html")
	public ModelAndView getUserScores(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/mine/scores");
		UserScorePo userScore = new UserScorePo();
		this.setPpt(request, userScore);
		userScore.setUserId(this.getUserIdFromSession(request));
		mv.addObject("scores", userScoreConnector.getUserScores(userScore).getData());
		mv.addObject("score", userScore);
		return mv;
	}
	
	/**
	 * 根据获取积分原因查询我的积分
	 * @return
	 */
	@RequestMapping("myScore.html")
	public List<UserScorePo> ambMembers(String code, HttpServletRequest request) {
		UserScorePo userScore = new UserScorePo();
		userScore.setUserId(this.getUserIdFromSession(request));
		userScore.setChangeReasonCode(code);
		this.setPpt(request, userScore);
		return userScoreConnector.getScores(userScore);
	}
	
	@RequestMapping("getUserScoresByUserId.html")
	public List<UserScorePo> getUserScoresByUserId(int userId, HttpServletRequest request) {
		PageParamTo ppt = null == request ? new PageParamTo() : getPageParam(request);
		UserScorePo userScore = new UserScorePo();
		userScore.setUserId(userId);
		userScore.setStart(ppt.getStart());
		userScore.setSize(ppt.getSize());
		ResultPageTo<UserScorePo> rpt = userScoreConnector.getUserScores(userScore);
		return rpt.getData();
	}
}